package com.hitqz.robot.api.business.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hitqz.robot.api.business.vo.PatrolResultSummaryVo;
import jakarta.servlet.http.HttpServletResponse;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author wengyx
 * @date 2024/8/26
 */
public class ExcelUtil {

    public static String getPatrolExcelFilePath(String basePath,Integer ticketsId){
        String dir = basePath + File.separator + "excel" + File.separator;
        if (!FileUtil.exist(dir)) {
            FileUtil.mkdir(dir);
        }
        return dir + ticketsId +"_finish"+".xlsx";
    }

    public static void response2Web(HttpServletResponse response, String word){
        response.reset();
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        try {
            Map<String, Object> map = Maps.newHashMap();
            map.put("code", 0);
            map.put("msg", word);
            map.put("data", null);
            response.getWriter().println(JSON.toJSONString(map));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static List <List<String>> head(PatrolResultSummaryVo summary){
        String taskName = summary.getTicketsName();
        String taskTime = DateUtil.format(summary.getStartTime(),"yyyy-MM-dd HH:mm:ss");
        String content = "总检测项数:"+summary.getTotalItemNum()
                +",正常数:"+summary.getNormalItemNum()
                +",异常数:"+summary.getAbnormalItemNum()
                +",识别失败数:"+summary.getVisionFailedItemNum()
                +",未检测数:"+summary.getWaitItemNum();
        List<List<String>> headTitles = Lists.newArrayList();
        //第一列，1/2/3/4/5/6/7行
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,"任务名称","任务开始时间","总结","序号") );
        //第二列，1/2/3/4/5/6/7行
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"房间名称" ) );
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"设备名称" ) );
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"巡检项名称" ) );
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"检测标准" ) );
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"检测时间" ) );
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"检测值" ) );
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"检测结果" ) );
        headTitles.add( Lists.newArrayList("智能巡检机器人巡检报告" ,taskName,taskTime,content,"图片" ) );
        return headTitles;
    }




}
